
col  = new Array()
row = new Array()
function loadmean(){
    SeekAllroute()
   SeekAllTickets()
  //  grafica();
}


function SeekAllTickets(){
    var argsArray=new Array();
    argsArray.push(newArg("Action","Consult"));
    sendRequest("../controller/controllergraph.jsp",argsArray,showdata);
}

function showdata()
 {
  
    if (isValidResponse(this))
    {

        var res=this.responseText;
        if(res!="")
        {
            var info=eval("("+res+")");
            for(i=0; i<info.data.length; i++){
            col.push(info.data[i].number)
            row.push(info.data[i].idRoute)
            }
            grafica();
        }

        else
            window.alert("Not Found!!");
    }
}


function SeekAllroute()
{
    var argsArray=new Array();
    argsArray.push(newArg("Action","Seek"));
    sendRequest("../controller/controllergraph.jsp",argsArray,show);
}

function show()
{

    var html='<table><tr><td align="center">ID RUTA</td><td align="center">CIUDAD ORIGEN</td><td align="center">CIUDAD DESTINO</td></tr>';
    if (isValidResponse(this))
    {

        var res=this.responseText;
        if(res!="")
        {
            var info=eval("("+res+")");
            for(i=0; i<info.data.length; i++){
                html+='<td> <input type="text" id="idRoute'+info.data[i].idRoute+'" value="'+info.data[i].idRoute+'"disabled="disabled">'
                html+='<td> <input type="text" id="namesource'+info.data[i].idRoute+'" value="'+info.data[i].source+'"disabled="disabled">'
                html+='<td> <input type="text" id="nameDestination'+info.data[i].idRoute+'" value="'+info.data[i].destination+'"disabled="disabled"></tr>'
            }
            html+='</table>'
            
            document.getElementById('listRoutes').innerHTML = html
        }

        else
            window.alert("Not Found!!");
    }
}



function grafica(){
   // var bar2 = new RGraph.Bar('bar2', [140, 150, 160, 150, 120, 150, 160, 140, 120, 160, 500]);
   var bar2 = new RGraph.Bar('bar2', col);
    bar2.Set('chart.background.barcolor1', 'white');
    bar2.Set('chart.background.barcolor2', 'white');
    bar2.Set('chart.title', 'Estadisticas Uso de Rutas');
    bar2.Set('chart.title.vpos', 0.6);
   // bar2.Set('chart.labels', ['Fred', 'Rich', 'Alex','John','Nick', 'Doug', 'Jaz', 'Pat', 'Baz', 'Bob','ffff']);
    bar2.Set('chart.labels',row);
    bar2.Set('chart.text.angle', 45);
    bar2.Set('chart.gutter', 35);
    bar2.Set('chart.colors', ['black']);
    bar2.Set('chart.key.position', 'gutter');
    bar2.Set('chart.text.size', 10);
    bar2.Set('chart.text.font', 'Georgia');
    bar2.Set('chart.text.angle', 45);
    bar2.Set('chart.grouping', 'stacked');

    if (!RGraph.isIE8()) {
        bar2.Set('chart.tooltips', ['Fred', 'Rich', 'Alex','John','Nick', 'Doug', 'Jaz', 'Pat', 'Baz', 'Bob']);
    }

    bar2.Draw()
}


